package com.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * 728. 自除数
 *
 * @author fy
 * @date 2022/3/31 16:17
 */
public class Solution728 {

    public List<Integer> selfDividingNumbers(int left, int right) {
        List<Integer> list = new ArrayList<>();
        for (int i = left; i <= right; i++) {
            if (isSelfDiv(i)) {
                list.add(i);
            }
        }
        return list;
    }

    private boolean isSelfDiv(int num) {
        int tmp = num;
        while (tmp > 0) {
            int tail = tmp % 10;
            if (tail == 0) {
                return false;
            }
            if (num % tail != 0) {
                return false;
            }
            tmp = tmp / 10;
        }
        return true;
    }

    public static void main(String[] args) {
        List<Integer> list = new Solution728().selfDividingNumbers(10, 22);
        System.out.println(list);
    }

}
